package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiTradeApplicationConfirmLetter;
import com.minimalist.common.entity.lindi.vo.tradeapplicationconfirmletter.LindiTradeApplicationConfirmLetterQueryVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 林地指标交易平台_交易申请确认函 映射层。
 *
 * @author 11987
 * @since 2025-06-06
 */
@Mapper
public interface LindiTradeApplicationConfirmLetterMapper extends BaseMapper<LindiTradeApplicationConfirmLetter>{

    /**
     * 根据ID查询交易申请确认函
     *
     * @param confirmLetterId 确认函ID
     * @return 交易申请确认函
     */
    default LindiTradeApplicationConfirmLetter selectTradeApplicationConfirmLetterByConfirmLetterId(Long confirmLetterId){
        return selectOneByQuery(QueryChain.create().eq(LindiTradeApplicationConfirmLetter::getConfirmLetterId, confirmLetterId));
    }

    /**
     * 分页查询交易申请确认函列表
     *
     * @param queryVO 查询条件
     * @return 分页结果
     */
    default Page<LindiTradeApplicationConfirmLetter> selectPageTradeApplicationConfirmLetterList(LindiTradeApplicationConfirmLetterQueryVO queryVO){
        return paginate(queryVO.getPageNum(), queryVO.getPageSize(),
                QueryWrapper.create()
                        .eq(LindiTradeApplicationConfirmLetter::getTradeApplicationId, queryVO.getTradeApplicationId())
                        .like(LindiTradeApplicationConfirmLetter::getConfirmLetterType, queryVO.getConfirmLetterType())
                        .like(LindiTradeApplicationConfirmLetter::getConfirmLetterCode, queryVO.getConfirmLetterCode())
                        .orderBy(LindiTradeApplicationConfirmLetter::getCreateTime, false));
    }

    /**
     * 根据交易申请ID查询交易申请确认函列表
     *
     * @param tradeApplicationId 交易申请ID
     * @return 交易申请确认函列表
     */
    default List<LindiTradeApplicationConfirmLetter> selectTradeApplicationConfirmLetterListByTradeApplicationId(
            Long tradeApplicationId){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiTradeApplicationConfirmLetter::getTradeApplicationId, tradeApplicationId)
                .orderBy(LindiTradeApplicationConfirmLetter::getId, false));
    }

    /**
     * 根据交易申请确认函ID查询交易申请确认函列表
     *
     * @param confirmLetterId 确认函ID
     * @return 交易申请确认函列表
     */
    default List<LindiTradeApplicationConfirmLetter> selectTradeApplicationConfirmLetterListByConfirmLetterId(Long confirmLetterId){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiTradeApplicationConfirmLetter::getConfirmLetterId, confirmLetterId)
                .orderBy(LindiTradeApplicationConfirmLetter::getId, false));
    }

    /**
     * 根据确认函编号查询交易申请确认函
     *
     * @param confirmLetterNo 确认函编号
     * @return 交易申请确认函
     */
    default LindiTradeApplicationConfirmLetter selectTradeApplicationConfirmLetterByConfirmLetterNo(String confirmLetterNo){
        return selectOneByQuery(QueryChain.create().eq(LindiTradeApplicationConfirmLetter::getConfirmLetterCode, confirmLetterNo));
    }
}
